import config from '@/config/config.js';
import http from '@/api/http.js'

let processStepRequest={
    showSteps(processId,page=1,limit=10,callBack){
// 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/processStep/list?page="+page + "&limit=" + limit;
            if(processId){
                    url += "&processId=" + processId;
            }
            console.log(url);
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    },countStep(processId,callBack){
        let token = localStorage.getItem("token");
        if(token){
            http.get(config.productionBaseUrl + "/processStep/count?processId=" + processId,callBack);
        }else{
            callBack(undefined);
        }
    },addStep(processStep,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/processStep/add";
            http.post(url,processStep,callBack);
        }else{
            callBack(undefined);
        }
    },editStep(processStep,beforeStepId,callBack){
    let token = localStorage.getItem("token");
    if(token){
        let url = config.productionBaseUrl + "/processStep/edit?beforeStepId=" + beforeStepId;
        http.post(url,processStep,callBack);
        }else{
        callBack(undefined);
        }
    },deleteStep(processId,processStepId,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/processStep/delete?processId="+processId + "&processStepId=" + processStepId;
            http.delete(url,callBack);
        }else{
            callBack(undefined);
        }
    },reDelete(stepIds,processId,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/processStep/reDelete?processId=" + processId;
            if(stepIds){
                stepIds.forEach(id=>url += '&stepIds=' + id);
            }
            http.delete(url,callBack);
        }else{
            callBack(undefined);
        }
    },download(download,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/processStep/download?processId=" + download.processId + "&name=" + download.fileName + "&address=" + download.address;
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    },showByOperationStepId(operationStepId,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.productionBaseUrl + "/processStep/showByOperationStepId?operationStepId=" + operationStepId;
            console.log(url);
            http.get(url, callBack);
        } else {
            callBack(undefined);
        }
    }
}

export default processStepRequest;